﻿using System;

using System.Reflection;



namespace IMath

{

    public interface ICalculator

    {

        int Add(int a, int b);

        int Subtract(int a, int b);

        int Multiply(int a, int b);

        int Divide(int a, int b);

    }

}



namespace Math

{

    using IMath;



    public class Calculator : ICalculator

    {

        public int Add(int a, int b) => a + b;

        public int Subtract(int a, int b) => a - b;

        public int Multiply(int a, int b) => a * b;

        public int Divide(int a, int b)

        {

            if (b == 0) throw new DivideByZeroException();

            return a / b;

        }

    }

}



class Program

{

    static void Main(string[] args)

    {

        Assembly assembly = Assembly.LoadFrom(@"Math.dll");

        Type type = assembly.GetType("Math.Calculator");

        object calculator = Activator.CreateInstance(type);



        Type iCalcType = typeof(IMath.ICalculator);

        MethodInfo add = iCalcType.GetMethod("Add");

        MethodInfo sub = iCalcType.GetMethod("Subtract");

        MethodInfo mul = iCalcType.GetMethod("Multiply");

        MethodInfo div = iCalcType.GetMethod("Divide");



        int a = 10, b = 5;

        Console.WriteLine($"{a}+{b}={add.Invoke(calculator, new object[] { a, b })}");

        Console.WriteLine($"{a}-{b}={sub.Invoke(calculator, new object[] { a, b })}");

        Console.WriteLine($"{a}×{b}={mul.Invoke(calculator, new object[] { a, b })}");

        Console.WriteLine($"{a}÷{b}={div.Invoke(calculator, new object[] { a, b })}");

    }

}
